package sending.lazyviewpager;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class LazyActivity extends AppCompatActivity {
    ViewPager viewPager;
    List<Fragment> fragmentList;
    ViewPagerAdapter viewPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lazy);
        initView();
    }

    private void initView() {
        viewPager = (ViewPager) findViewById(R.id.my_vp);
        fragmentList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            TestFragment testFragment = TestFragment.newInstance(i,i==0?false:true);
            fragmentList.add(testFragment);
        }
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        viewPager.setAdapter(viewPagerAdapter);
//        viewPager.setOffscreenPageLimit(fragmentList.size());


    }

}
